package seekting.demo2017.activity;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import seekting.demo2017.AppEnv;

/**
 * Created by seekting on 17-5-18.
 */

public class SharedPrefActivityOther extends Activity {

    public static final boolean DEBUG = AppEnv.bAppdebug;
    public static final String TAG = "SharedPrefActivityOther";
    public static final String KEY_SEEKTING = "key_seekting";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setOrientation(LinearLayout.VERTICAL);

        Button save = new Button(this);
        save.setText("save");
        linearLayout.addView(save);

        Button read = new Button(this);
        read.setText("read");
        linearLayout.addView(read);


        Button goOther = new Button(this);
        goOther.setText("goOtherProcess");
        linearLayout.addView(goOther);

        setContentView(linearLayout);


        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences sharedPreferences = getSharedPreferences("seekting", Context.MODE_PRIVATE);
                SharedPreferences.Editor e = sharedPreferences.edit();
                e.putString(KEY_SEEKTING, "1");
                e.apply();
            }
        });
        read.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences sharedPreferences = getSharedPreferences("seekting", Context.MODE_PRIVATE);
                String str = sharedPreferences.getString(KEY_SEEKTING, "null");

                if (DEBUG) {
                    Log.d(TAG, "onClick." + str);
                }

            }
        });
        goOther.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

    }
}
